﻿using System.Linq.Expressions;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.PersistenceObject;

namespace WMS.FC.Domain.Repository
{
    public interface IRepositoryBase
    {
        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="entity"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        Task<int> Insert<TSource>(TSource entity, UserInfo userInfo) where TSource : POBase;

        /// <summary>
        /// 插入
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="entityList"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        Task<int> Insert<TSource>(List<TSource> entityList, UserInfo userInfo) where TSource : POBase;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="entity"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        Task<int> Update<TSource>(TSource entity, UserInfo userInfo) where TSource : POBase;

        /// <summary>
        /// 更新
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="entityList"></param>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        Task<int> Update<TSource>(List<TSource> entityList, UserInfo userInfo) where TSource : POBase;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<int> Delete<TSource>(long id) where TSource : POBase;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<int> Delete<TSource>(TSource entity) where TSource : POBase;

        /// <summary>
        /// 删除
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<int> Delete<TSource>(Expression<Func<TSource, bool>> expression) where TSource : POBase;

        /// <summary>
        /// 获取全部
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <returns></returns>
        Task<List<TSource>> GetAll<TSource>() where TSource : POBase;

        /// <summary>
        /// 根据条件查找
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="whereExpression"></param>
        /// <returns></returns>
        Task<List<TSource>> FindByCondition<TSource>(Expression<Func<TSource, bool>> whereExpression) where TSource : POBase;

        /// <summary>
        /// 根据条件查找排序
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="whereExpression"></param>
        /// <param name="keySelector"></param>
        /// <returns></returns>
        Task<List<TSource>> FindByConditionOrderby<TSource, TKey>(Expression<Func<TSource, bool>> whereExpression, Expression<Func<TSource, TKey>> keySelector) where TSource : POBase;

        /// <summary>
        /// 根据条件查找逆向排序
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="whereExpression"></param>
        /// <param name="keySelector"></param>
        /// <returns></returns>
        Task<List<TSource>> FindByConditionOrderByDescending<TSource, TKey>(Expression<Func<TSource, bool>> whereExpression, Expression<Func<TSource, TKey>> keySelector) where TSource : POBase;

        /// <summary>
        /// 根据ID查找
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<TSource?> FindById<TSource>(long id) where TSource : POBase;

        /// <summary>
        /// 根据条件获取数量
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<int> GetCount<TSource>(Expression<Func<TSource, bool>> expression) where TSource : POBase;
    }
}
